home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 4 / Example 4.8 / terrain.h < prev   
Encoding:
C/C++ Source or Header  |  2006-06-29  |  1.2 KB  |  63 lines

  1. #ifndef _TERRAIN_
  2. #define _TERRAIN_
  3.  
  4. #include <d3dx9.h>
  5. #include <vector>
  6. #include "heightmap.h"
  7. #include "debug.h"
  8. #include "shader.h"
  9.  
  10. struct TERRAINVertex
  11. {
  12.     TERRAINVertex(){}
  13.     TERRAINVertex(D3DXVECTOR3 pos, D3DXVECTOR2 _uv1, D3DXVECTOR2 _uv2)
  14.     {
  15.         position = pos;
  16.         normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
  17.         uv1 = _uv1;
  18.         uv2 = _uv2;
  19.     }
  20.  
  21.     D3DXVECTOR3 position, normal;
  22.     D3DXVECTOR2 uv1, uv2;
  23.  
  24.     static const DWORD FVF;
  25. };
  26.  
  27. struct PATCH{
  28.     PATCH();
  29.     ~PATCH();
  30.     void Release();
  31.     HRESULT CreateMesh(HEIGHTMAP &hm, RECT source, IDirect3DDevice9* Dev);
  32.     void Render();
  33.  
  34.     IDirect3DDevice9* m_pDevice;
  35.     ID3DXMesh *m_pMesh;
  36. };
  37.  
  38. class TERRAIN{
  39.     friend class APPLICATION;
  40.     public:
  41.         TERRAIN();        
  42.         void Init(IDirect3DDevice9* Dev, INTPOINT _size);
  43.         void Release();
  44.         void GenerateRandomTerrain(int numPatches);
  45.         void CreatePatches(int numPatches);
  46.         void CalculateAlphaMaps();
  47.         void Render();
  48.  
  49.     private:
  50.  
  51.         INTPOINT m_size;
  52.         IDirect3DDevice9* m_pDevice; 
  53.  
  54.         HEIGHTMAP *m_pHeightMap;
  55.         std::vector<PATCH*> m_patches;
  56.         std::vector<IDirect3DTexture9*> m_diffuseMaps;
  57.         IDirect3DTexture9* m_pAlphaMap;
  58.         SHADER m_terrainPS;
  59.  
  60.         D3DMATERIAL9 m_mtrl;
  61. };
  62.  
  63. #endif